package values.item
{
import com.adobe.utils.DictionaryUtil;

import flash.utils.Dictionary;

/**
 * UpgradebleItemTemplateValue
 * @author jliang
 *
 */
public class UpgradebleItemTemplateValue extends ItemTemplateValue
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function UpgradebleItemTemplateValue()
	{
		super();
	}
	
	protected var _upgrades:Dictionary; /* ItemUpgradeValue */
	
	public function get upgrades():Dictionary
	{
		return _upgrades;
	}
	
	[Data(type="mapping", 
		  mapping="upgrade.level", 
		  ref="values.item.ItemUpgradeValue",
		  way="one_to_more",
		  object="flash.utils.Dictionary",
          key="@index")]
	public function set upgrades(value:Dictionary):void
	{
		_upgrades = value;
	}
	
	public function getUpgradeByLevel(lvl:int):ItemUpgradeValue
	{
		return upgrades[lvl];
	}
	
	protected var _maxLevel:int = -1;
	
	public function get maxLevel():int
	{
		if (_maxLevel == -1)
		{
			_maxLevel = DictionaryUtil.getValues(upgrades).length;
		}
		return _maxLevel;
	}
}
}